package org.budo.mongo.filter.log;

import java.util.Arrays;

import org.budo.mongo.filter.AbstractMongoFilter;
import org.budo.mongo.filter.MongoFilterChain;

import com.mongodb.CommandResult;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.WriteResult;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
public class MongoLogFilter extends AbstractMongoFilter {
    @Override
    public DBCollection db_getCollection(MongoFilterChain filterChain, DB db, String $0) {
        log.info("#59 dbCollection_find, db={}, name={}", db, $0);

        return super.db_getCollection(filterChain, db, $0);
    }

    @Override
    public long dbCollection_count(MongoFilterChain filterChain, DBCollection dbCollection, DBObject $0) {
        log.info("#28 dbCollection_count, dbCollection={}, documents={}", dbCollection, $0);

        return super.dbCollection_count(filterChain, dbCollection, $0);
    }

    @Override
    public DBCursor dbCollection_find(MongoFilterChain filterChain, DBCollection dbCollection, DBObject $0) {
        log.info("#45 dbCollection_find, dbCollection={}, query={}", dbCollection, $0);

        return super.dbCollection_find(filterChain, dbCollection, $0);
    }

    @Override
    public DBCursor dbCollection_find(MongoFilterChain filterChain, DBCollection dbCollection, DBObject $0, DBObject $1) {
        log.info("#52 dbCollection_find, dbCollection={}, query={}, projection={}", dbCollection, $0, $1);

        return super.dbCollection_find(filterChain, dbCollection, $0, $1);
    }

    @Override
    public DBObject dbCollection_findOne(MongoFilterChain filterChain, DBCollection dbCollection, DBObject $0, DBObject $1) {
        log.info("#66 dbCollection_find, dbCollection={}, query={}, projection={}", dbCollection, $0, $1);

        return super.dbCollection_findOne(filterChain, dbCollection, $0, $1);
    }

    @Override
    public WriteResult dbCollection_insert(MongoFilterChain filterChain, DBCollection dbCollection, DBObject[] $0) {
        log.info("#19 dbCollection_insert, dbCollection={}, documents={}", dbCollection, Arrays.toString($0));

        return super.dbCollection_insert(filterChain, dbCollection, $0);
    }

    @Override
    public WriteResult dbCollection_save(MongoFilterChain filterChain, DBCollection dbCollection, DBObject $0) {
        log.info("#73 dbCollection_save, dbCollection={}, document={}", dbCollection, $0);

        return super.dbCollection_save(filterChain, dbCollection, $0);
    }

    @Override
    public DB mongoClient_getDB(MongoFilterChain filterChain, MongoClient mongoClient, String $0) {
        log.info("#37 mongoClient_getDB, mongoClient={}, dbName={}", mongoClient, $0);

        return super.mongoClient_getDB(filterChain, mongoClient, $0);
    }

    @Override
    public CommandResult db_command(MongoFilterChain filterChain, DB db, DBObject $0) {
        log.info("#37 db_command, db={}, command={}", db, $0);

        return super.db_command(filterChain, db, $0);
    }
}